<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        4. 完善以下getData函数，实现外部对data数据的获取
        function getData(){
            setTimeout(()=>{
                let data = {code:200,msg:'success',data:[]}
            },1000)
        }
     -->
</head>
    <script>
        // 1.回调函数
        // function getData(cb){
        //     setTimeout(()=>{
        //         let data = {code:200,msg:'success',data:[]}
        //         cb(data)
        //     },1000)

        // }
        // getData(function(a){
        //     console.log(a)
        // })

        // 2.Promise方法
        function getData(){
            return new Promise(function(resolve,reject){
                setTimeout(()=>{
                    let data = {code:200,msg:'success',data:[]}
                    resolve(data)
                },1000)
            })
        }
        ;(async ()=>{
           const result = await getData()
           console.log(result)
        })();
       
        
    </script>
<body>
</body>
</html>